package com.hdoit.apollo.web.statistics.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hdoit.apollo.logical.statistics.model.StockChangeRecord;
import com.hdoit.apollo.logical.statistics.service.IStockChangeStatisticsService;
import com.hdoit.apollo.logical.viewmodel.statistics.StockChangeRecordSearch;
import com.tennetcn.authority.component.web.BaseController;
import com.tennetcn.data.message.PagerModel;
import com.tennetcn.web.message.WebManageContainer;

@Controller
@RequestMapping(value = "/statistics/stockChangeStatistics/")
public class StockChangeStatisticsController extends BaseController{
    @Override
    public String getRoutePath() {
        return "areas/statistics/stockChangeStatistics/";
    }
    
    private final String indexViewName="index";
    private final String outputViewName="output";
    
	@Autowired
	private IStockChangeStatisticsService stockChangeStatisticsService;

	
    @RequestMapping(value = indexViewName, method = { RequestMethod.GET,RequestMethod.POST })
    public String index(Model model,PagerModel pagerModel,StockChangeRecordSearch search,boolean ajaxPost){

    	pagerModel.setTotalAmount(stockChangeStatisticsService.getStockChangeRecordList(search,null).size());
        List<StockChangeRecord> stockChangeRecords=stockChangeStatisticsService.getStockChangeRecordList(search,pagerModel);
       

        model.addAttribute(WebManageContainer.PAGERKEY, pagerModel);
        model.addAttribute("stockChangeRecords", stockChangeRecords);
        model.addAttribute("stockChangeRecordSearch", search);

        if(ajaxPost){
            return view(outputViewName);
        }

        return view(indexViewName);
    }
}

